<!DOCTYPE html>
<html lang="en">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<head>
    <title>Moto - 通用添加</title>
    <meta charset="utf-8">

    <!--
        若页面需默认用极速核，增加标签：<meta name="renderer" content="webkit">
        若页面需默认用ie兼容内核，增加标签：<meta name="renderer" content="ie-comp">
        若页面需默认用ie标准内核，增加标签：<meta name="renderer" content="ie-stand">
    -->
    <meta name="renderer" content="ie-comp">
    <meta http-equiv="X-UA-Compatible" content="IE=9;IE=EDGE">
    <meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <script type="text/javascript" src="../js/jquery-1.9.0.min.js"></script>
    <script type="text/javascript" src="../js/layer/layer.js"></script>
    <script type="text/javascript" src="../js/kindeditor-4.1.10/kindeditor.js"></script>
    <%--<script type="text/javascript" src="../js/parse-excel.js"></script>--%>
    <style type="text/css">
        .body_div {
            text-align: center;
        }

        .table-detail {
            text-align: center;
            border: 1px solid rgb(228, 228, 228);
        }

        th {
            text-align: center;
            background-color: rgb(230, 230, 230);
            border-bottom: 1px solid rgb(228, 228, 228);
            font-weight: bold;
            color: rgb(90, 90, 90);
            padding: 5px 8px;
        }

        td {
            text-align: center;
            border: 1px solid rgb(228, 228, 228);
            padding: 5px 8px;
            color: rgb(56, 56, 56);
            font-size: 15px;
            width: 210px;
        }

        td input {
            width: 100%;
            height: 1.5em;
            line-height: 1.5em;
        }

        a {
            text-decoration: none;
            margin: 0 1.5em;
        }

        textarea {
            width: 100%;
            resize: none;
        }

        .imgsc {
            width: 25px;
            height: 25px;
        }

        #personDetail th {
            width: 33%;
        }
    </style>
</head>

<body>
<form id="motoForm" name="motoForm" action="<%=basePath%>/part/save" method="post" enctype="multipart/form-data">
    <div class="body_div">
        <input type="hidden" name="sid" id="sid" value="${SRModel.sid}"/>
        <input type="hidden" name="img_url" value="${SRModel.img_url}"/>
        <input type="hidden" name="rkeys_str" id="rkeys_str" value=""/>
        <input type="hidden" name="rvals_str" id="rvals_str" value=""/>


        <table class="table-detail" align="center">
            <tr>
                <th>名称</th>
                <td><input name="moto_name" id="moto_name" onBlur="ajaxCkName();" value="${SRModel.moto_name}"/></td>
                <th>品牌</th>
                <td><input name="moto_brand" id="moto_brand" value="${SRModel.moto_brand}"/></td>
            </tr>
            <th>型号</th>
            <td><input name="moto_model" id="moto_model" value="${SRModel.moto_model}"/></td>
            </tr>
            <tr>
                <th>主类型</th>
                <td>
                    <input type="hidden" name="moto_type" id="moto_type" value="${SRModel.moto_type}"/>
                    <select name="moto_type_dep" id="moto_type_dep" onchange="querySonData();" style="width:100%;">
                        <option value=""></option>
                    </select>
                </td>
                <th>子类型</th>
                <td>
                    <input type="hidden" name="moto_two_type" id="moto_two_type" value="${SRModel.moto_two_type}"/>
                    <select name="moto_two_type_dep" id="moto_two_type_dep"  style="width:100%;">

                    </select>
                </td>
            </tr>
            <tr>
                <th>采集地址</th>
                <td colspan="3"><input name="moto_url" id="moto_url" onBlur="ajaxCkUrl();" value="${SRModel.moto_url}"/>
                </td>
            </tr>
            <tr>
                <th>图片</th>
                <td>
                    <input type="file" value="选择图片" id="img_1" name="img_1"/>
                </td>
                <td style="vertical-align: middle;">
                    <c:if test="${SRModel.img_url !=null and SRModel.img_url!=''}">
                        <a href="<%=basePath%>${SRModel.img_url}" target="_blank">
                            <img class="imgsc" id="imgPath1" src="<%=basePath%>${SRModel.img_url}"/>
                        </a>
                    </c:if>
                </td>
                <td>
                    注:重新选择图片上传可替换原图
                </td>
            </tr>

            <tr style="width:100%;">
                <td colspan="4" style="width:100%;">

                    <table id="pd" class="table-detail" align="center" style="width:100%;">
                        <tbody>
                        <tr id="pwds">
                            <td colspan="2">参数名称</td>
                            <td colspan="2">参数值</td>
                            <td colspan="2"><a href="javascript:addRow();">【添加】</a></td>
                        </tr>
                        <c:forEach items="${paramList}" var="paramlist" varStatus="status">
                            <tr id="app${status.index}">
                                <td colspan="2">
                                    <input id="rkey${status.index}"  name="rkey" value="${paramlist.param_name}" psid="${paramlist.sid}" />
                                </td>
                                <td colspan="2">
                                    <input id="rval${status.index}"  name="rval" value="${paramlist.param_value}" psid="${paramlist.sid}" />
                                </td>
                                <td colspan="2">
                                    <a href="javascript:delRow(${status.index});" >【删除】</a>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </td>
            <tr>
                <td colspan="4">
                    <a href="javascript:editSave();">[保存]</a>
                    <a href="javascript:window.close();">[关闭]</a>
                    <%--<a href="javascript:history.go(-1);">[返回]</a>--%>
                </td>
            </tr>

        </table>
    </div>
</form>
</body>
<script type="text/javascript">
    var keyId = 0;
    window.onload = function () {
        queryData();
        changeMethod();
        querySonData($("#moto_type_dep").val());
        changeShipMethod();
    };

    function changeMethod(){
        $("#moto_type_dep option").each(function(){ //遍历全部option
            if($(this).text()=='${SRModel.moto_type}'){
                $(this).attr('selected',true);
            }
        });
    }
    function changeShipMethod(){
        $("#moto_two_type_dep option").each(function(){ //遍历全部option
            if($(this).text()=='${SRModel.moto_two_type}'){
                $(this).attr('selected',true);
            }
        });
    }


    function addRow() {
        $("#pd tbody").append('<tr id="app' + keyId + '"><td colspan="2">' + '<input id="index' + keyId + '" index=' + keyId + ' name="rkey" value=""/></td>' +
                '<td colspan="2"><input id="index' + keyId + '" index=' + keyId + ' name="rval" value=""/></td>' +
                '<td  colspan="2">' +
                '<a href="javascript:delRow(' + keyId + ');">【删除】</a>' +
                '</td></tr>'
        );
        keyId++;
    }

    function delRow(id) {
        $('#app' + id + '').remove();
    }

    //主类型
    function queryData() {
        $.ajax({
            type: "POST",
            url: "<%=basePath%>/api/data/parent",
            data: {
                'codetype': "GoodsType",
                'pid': 0,
            },
            dataType: 'json',
            cache: false,
            async: false,
            success: function (data) {
                var province = eval("(" + data.data + ")"); //后台数据
                for (var p in province) {
                    var val = province[p].dataname;
                    var sid = province[p].sid;

                    $("#moto_type_dep").append("<option value='" + sid + "'>" + val + "</option>");

                }
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status + " | " + XMLHttpRequest.readyState + "|" + textStatus);
            }
        });
    }


    //子类型
    function querySonData(sonid) {
        $("#moto_two_type_dep").empty();//清空
        if(sonid == undefined || sonid==null || sonid == '' ){
            sonid =$('#moto_type_dep option:selected').val();
        }
        $.ajax({
            type: "POST",
            url: "<%=basePath%>/api/data/parent",
            data: {
                'codetype': "GoodsType",
                'pid': sonid,
            },
            dataType: 'json',
            cache: false,
            async: false,
            success: function (data) {
                var province = eval("(" + data.data + ")"); //后台数据
                for (var p in province) {
                    var val = province[p].dataname;
                    $("#moto_two_type_dep").append("<option value='" + sid + "'>" + val + "</option>");
                }
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status + " | " + XMLHttpRequest.readyState + "|" + textStatus);
            }
        });
    }

    function editSave() {
        $("#moto_type").val($("#moto_type_dep").find("option:selected").text());
        $("#moto_two_type").val($("#moto_two_type_dep").find("option:selected").text());
        var rkeys_str = "";
        var rvals_str = "";
        var indexSize = $("input[name='rkey']").length;
        $("input[name='rkey']").each(function () {
            rkeys_str += $(this).val() + ",";
        });
        $("input[name='rval']").each(function () {
            rvals_str += $(this).val() + ",";
        });
//        var rkeys = $("input[name='rkey']").val();
//        var rvals = $("input[name='rval']").val();
        $("#rkeys_str").val(rkeys_str);
        $("#rvals_str").val(rvals_str);
        document.motoForm.action = "<%=basePath%>part/save";
        document.motoForm.submit();
    }


    var moto_name_flag = false;
    function ajaxCkName() {
        var sid = $("#sid").val();
        var moto_name = $("#moto_name").val();
        if (moto_name == "") {
            return;
        }
        $.ajax({
            type: "POST",
            url: "<%=basePath%>ajax/ck/name",
            data: {
                'sid': sid,
                'moto_name': moto_name,
                'tm': new Date().getTime()
            },
            dataType: 'json',
            cache: false,
            async: false,
            success: function (data) {
                if (data.code == 0) {
                    moto_name_flag = true;//可用
                } else {
                    moto_name_flag = false;
                    layer.msg("该型号名称已存在");
                }
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status + " | " + XMLHttpRequest.readyState + "|" + textStatus);
            }
        });
    }


</script>
</html> 

